const Server = require('webpack-dev-server');
const webpack = require('webpack');
const { hasEnvironment } = require('./utils');

if (!hasEnvironment()) {
  throw Error('jjb.script[server]: 启动server需要提供NODE_ENV变量，请确认你所运行的脚本是否正确？');
}

const config = require('./config')('development');

new Server({
  host: config.server.host || '127.0.0.1',
  port: config.server.port || '8080',
  headers: {
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': '*',
    'Access-Control-Allow-Headers': '*'
  },
  compress: true,
  client: {
    overlay: {
      errors: true,
      warnings: true
    }
  },
  historyApiFallback: {
    disableDotRule: true
  }
}, webpack(config.webpack)).startCallback(() => console.log('jjb.server 服务已启动，正在编译。'));
